/* 
 * Convert matrix in text format into binary (floating point) format. 
 */
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "common.h"

int main(int argc, char **argv) {
   FILE *fout;
   int col,row,padded_row;
   float *M;

   if (argc < 3) {
      fprintf(stderr,"Usage: %s <txt> <raw>\n",argv[0]);
      exit(1);
   } 

   M = read_matrix(argv[1],TILESIZE,&row,&col,&padded_row);

   if ((fout = fopen(argv[2],"w")) == NULL) {
      fprintf(stderr,"Cannot write file %s\n",argv[2]); 
      exit(1);
   }
   int size = fwrite(M,sizeof(float),row*col,fout);
   if (size != row*col) {
      fprintf(stderr,"Fail to write data into file %s\n",argv[2]);
      exit(1);
   }
   printf("Data are successfully written into file %s\n",argv[2]);

   fclose(fout);
}
